package cz.cvut.fit.mi_paa.bucket.strategy;

import cz.cvut.fit.mi_paa.abs.Context;
import cz.cvut.fit.mi_paa.bucket.BucketInstance;

import java.util.PriorityQueue;
import java.util.Queue;

/**
 * Created with IntelliJ IDEA.
 * User: milos
 * Date: 20.11.12
 * Time: 8:29
 * To change this template use File | Settings | File Templates.
 */
public class FinishedBucketsBucketStrategy extends BucketStrategy {
    public FinishedBucketsBucketStrategy(Context context) {
        super(context);
    }

    @Override
    public Queue getQueue() {
        return new PriorityQueue(QUEUE_LENGTH,new BucketComparator(){

            @Override
            public int compare(BucketInstance o1, BucketInstance o2) {
                return Double.compare(o2.getScore(), o1.getScore());
            }
        });
    }

    @Override
    public BucketScoreGenerator getScoreGenerator() {
        return new BucketScoreGenerator() {
            @Override
            public double getScore(BucketInstance instance) {
                int score = 0;
                for (int i=0;i<instance.getNumBuckets();i++) {
                    if(instance.getEndConfiguration()[i] == instance.getBuckets()[i].getVolume()) {
                        score++;
                    }
                }
                return score;
            }
        };
    }
}
